package com.ihisomp.service.impl;

import com.ihisomp.entity.SysGetNo;
import com.ihisomp.mapper.SysGetNoMapper;
import com.ihisomp.service.ISysGetNoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ihisomp.util.ComUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;

/**
 * 标题: SysGetNoServiceImpl.java
 * 业务描述: 系统取号规则 服务实现类
 * 作者: zy
 * 日期: 2021/9/13
 * 版本: V1.0
 */
@Service
public class SysGetNoServiceImpl extends ServiceImpl<SysGetNoMapper, SysGetNo> implements ISysGetNoService {

    /**
     * 获得取号数据
     *
     * @param getNoKey
     * @return
     */
    @Override
    public String getSysNo(String getNoKey) {
        // 查询取号数据
        Map map = new HashMap();
        map.put("table_name", getNoKey);
        // 获取存储过程的返回值
        Map resultMap = baseMapper.getSysNo(map);
        if (resultMap == null) {
            return ComUtil.createPrimaryKey();
        }
        String nextNo = (String) resultMap.get("out_no");
        if (StringUtils.isBlank(nextNo)) {
            return ComUtil.createPrimaryKey();
        }
        return nextNo;
    }
}
